package Communication;

import java.util.Observable;
import java.util.PriorityQueue;
import java.util.Queue;

/**
 * 
 * @author lhy
 *
 */
public class Buffer extends Observable {
	private Queue<Message> messages;
	private static Buffer instance;

	private Buffer ( ) {
		messages = new PriorityQueue<Message> ( );
	}

	public void addMessage ( Message message ) {
		messages.add ( message );
		setChanged ( );
		notifyObservers ( );
	}

	public static Buffer getInstance ( ) {
		if ( instance == null )
			instance = new Buffer ( );
		return instance;
	}

	public Message getMessage ( ) {
		return (Message)messages.poll ( );
	}

	public boolean isEmpty ( ) {
		return messages.isEmpty ( );
	}
}
